package com.zhimeng.personal.utils.views;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.zhimeng.personal.R;

/**
 * Created by sunzhimeng on 10/31/17.
 */

public class LocMarkerView extends RelativeLayout {
    private Context context;
    private RelativeLayout  backgroundView;
    private ImageView frontVeiw;

    public void setBackgroundView(int drawableRes) {
        backgroundView.setBackgroundResource(drawableRes);
    }

    public void setFrontVeiw(Bitmap bitmap) {
        frontVeiw.setImageBitmap(bitmap);
    }

    public LocMarkerView(Context context) {
        super(context);
        initView(context);
    }
    public void isMarkerSelected(boolean isSelected){
        if (isSelected) {
            showAsSelected();
        }else showAsUnSelected();

    }

    private void showAsUnSelected() {
        backgroundView.setSelected(false);
    }

    private void showAsSelected() {
        backgroundView.setSelected(true);
    }


    public LocMarkerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        this.context=context;
        View.inflate(context, R.layout.loc_marker_view, this);
        backgroundView= (RelativeLayout) findViewById(R.id.iv_markout);
        GradientDrawable background = (GradientDrawable) backgroundView.getBackground();
        background.setColor(Color.parseColor("#A1A1FF"));
        frontVeiw= (ImageView) findViewById(R.id.iv_markinner);
        backgroundView.setSelected(false);
    }


}


